<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Kowcore
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: ObjectRate.php 2011-03-09 08:45:41Z idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Kowcore
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 */

class Kowcore_View_Helper_ObjectRate extends Zend_View_Helper_Abstract {
	
	protected $_name;
	
	public function objectRate(Core_Model_Item_Abstract $object, $isAllowed = true, $size = 'normal', $details = true, $runonce = true) {
		if (! $object->getIdentity ()) {
			return '';
		}
		
		$viewer = Engine_Api::_ ()->user ()->getViewer ();
		
		$isAllowed = $isAllowed && (! Engine_Api::_ ()->kowcore ()->isRated ( $object )) && ( bool ) $viewer->getIdentity () && ( bool ) (! $object->isOwner ( $viewer ));
		
		if (isset ( $object->cnt ) && isset ( $object->avg )) {
			$score = $object->avg;
			$cnt = $object->cnt;
		} else {
			$info = Engine_Api::_ ()->kowcore ()->getRateInfo ( $object );
			$score = $info ['score'];
			$cnt = $info ['cnt'];
			if (! $score) {
				$score = 0;
			}
			if (! $cnt) {
				$cnt = 0;
			}
		}
		
		$tpl = 'helper/object-rate.tpl';
		if ($size == 'small') {
			$tpl = 'helper/object-rate-small.tpl';
		}
		
		return $this->view->partial ( $tpl, 'kowcore', array ('object' => $object, 'score' => $score, 'count' => $cnt, 'viewer' => $viewer, 'isAllowed' => $isAllowed, 'details' => $details, 'runonce' => $runonce ) );
	}

}